package com.yanqu.road.dao.impl.activity.shuihucard;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.activity.shuihu.config.ShuiHuCardConfig;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class ShuiHuCardConfigDaoImpl extends TempDao {

    public static String getShuiHuCardConfigSql = "select * from t_s_activity_shuihu_card where activityId = ?";

    public Map<Integer, ShuiHuCardConfig> getShuiHuCardConfigMap(int activityId) {
        Map<Integer, ShuiHuCardConfig> map = new ConcurrentHashMap<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getShuiHuCardConfigSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                ShuiHuCardConfig shuiHuCardConfig = new ShuiHuCardConfig();
                shuiHuCardConfig.setActivityId(rs.getInt("activityId"));
                shuiHuCardConfig.setId(rs.getInt("id"));
                shuiHuCardConfig.setQuality(rs.getInt("quality"));
                shuiHuCardConfig.setScore(rs.getInt("score"));
                shuiHuCardConfig.setDecomposePoint(rs.getInt("decomposePoint"));
                shuiHuCardConfig.setComposePoint(rs.getInt("composePoint"));
                shuiHuCardConfig.setWeight(rs.getInt("weight"));
                shuiHuCardConfig.setName(rs.getString("name"));
                shuiHuCardConfig.setDesc(rs.getString("desc"));
                shuiHuCardConfig.setIcon(rs.getString("icon"));
                shuiHuCardConfig.setSort(rs.getInt("sort"));
                map.put(shuiHuCardConfig.getId(), shuiHuCardConfig);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return map;
    }

}
